
	    var count1 = 0;
		//医嘱另存为方案
		function saveFangan()
		{
			var bck01a = bck01;
			//----------------------
			var bbx1 = {};
			//bbx1.bbx01 = '0';
			bbx1.bda01 = '9';
			bbx1.bdo01 = $("#fangan_fenlei").find("option:selected").val();
			bbx1.bbx04 = new Date().getTime();//编号
			bbx1.bbx05 = $("#fangan_name").val();//
			if(!($("#fangan_fenlei").val())){
				layer.tips('请选择方案分类', '#fangan_fenlei');
				return false;
			}
			if(!bbx1.bbx05){
				layer.tips('请填写方案名称', '#fangan_name');
				return false;
			}
			bbx1.bbx06 = "";//
			bbx1.bdg02 = "";//
			bbx1.bbx08 = "";//
			bbx1.bbx09 = 0;//
			bbx1.abw01 = "0";//
			bbx1.bbx11 = "1";//
			bbx1.bbx12 = "0";//
			bbx1.bbx13 = "";//
			bbx1.bbx14 = "0";//
			bbx1.bbx15 = $(".fangan_radio:checked").val();//
			bbx1.acf01 = "1";//
			bbx1.bbx17 = "1";//
			bbx1.bbx18 = "0";//
			bbx1.bbx19 = "";//
			bbx1.bbx20 = "0";//
			bbx1.bbx21 = "0";//
			bbx1.bbx30 = 0;//
			bbx1.bbx36 = 0;//
			bbx1.bbx46 = 0;//
			bbx1.bcw01 = "0";//
			bbx1.bce01 = bce01;//
			bbx1.bbx25 = "9999-12-31";//
			bbx1.acf01 = "1";//
			layer.msg('保存中....', {icon: 16,skin: 'layui-layer-msg16',shade: [0.1, '#393D49'],time:0}); 
			var bdk1Arr = [];
			var bdk1 = {};
			bdk1.bdk03 = $("#fangan_name").val();//方案名称
			bdk1.bdk06 = 1;;//方案别名
			var bdk2 = {};
			bdk2.bdk03 = $("#fangan_bieming").val();//方案名称
			bdk2.bdk06 = 9;//方案别名
			bdk1Arr.push(bdk1);
			bdk1Arr.push(bdk2);
			var bef1Arr = [];
			var bar1Arr = [];
			var bar1 = {};
			bar1.bck01 = bck01;
			bar1Arr.push(bar1);
			var bef1 = [];
			GetBef1(bef1);//西药
			GetBef3(bef1);//中药
			GetBefL(bef1);//检验
			GetBefE(bef1);//检查
			GetBefS(bef1);//手术
			GetBefT(bef1);//治疗
			///////////////////////////////////////////////////////华丽的分割线
			if(bef1.length==0)
			{
				layer.msg('没有需要保存的方案，请检查！', {
					time : 2000,
					icon : 0,
					skin: 'layui-layer-msg0'
				});
			}
			else
			{
				$.ajax({
					url:kzzxUrl+"/bef1/saveBef1",
					type: "post",
					data: {bbx1:JSON.stringify(bbx1),bdk1:JSON.stringify(bdk1Arr),bef1:JSON.stringify(bef1),bar1:JSON.stringify(bar1Arr)},
					dataType:'text',
					timeout:1000,
					success:function(data)
					{
						
						if(data=="SUCCESS"){
							layer.msg("保存成功", {
								time : 2000,
								icon : 1,
								skin: 'layui-layer-msg1'
							});
							layer.close(saveFangan_index);
//							parent.layer.close(parent.layer.getFrameIndex(window.name));
						}else{
							layer.msg(data, {
								time : 2000,
								icon : 2,
								skin: 'layui-layer-msg2'
							});
						}
					},
					error: function(XMLHttpRequest, textStatus, errorThrown) 
					{
						if (textStatus=='timeout') {
							layer.msg('控制中心服务器连接失败！', {
								time : 2000,
								icon : 0,
								skin: 'layui-layer-msg0'
							});
						}
						else
						{
							layer.msg(textStatus, {
								time : 2000,
								icon : 2,
								skin: 'layui-layer-msg2'
							});
						}
					}
				});
			}
		}
		
		//西药
		function GetBef1(bef1) 
		{
			 var bck01a = bck01;
			 var rownr = 1;
			 var zuValue = 1;
			 $("#west_medicine_table tbody tr").each(function(i)
			 { 
				 var tdArr = $(this);
				 var flag = tdArr.find(".xiyao_yznr").val(); //如果医嘱内容为空，则不保存
				 if (flag != "" && flag !=undefined) 
				 {
					  var bda01 = "1";
					  var zu = tdArr.find(".xiyao_zu").text();
						 if (!zu) //同组
						 {
							 rownr++;
						 }
						 else//非同组--组号递增
						 {
							 zuValue++;
						 }
					  //给药途径
				  if (zu)
					{
					  var temp1 = configData1(tdArr,vaa01,vac01);//初始化公共参数
					  temp1.rownr="0";//顺序
					  temp1.bbx01c = tdArr.find(".xiyao_geiyao").find("select option:selected").attr("id");//项目ID
					  temp1.bef07 = tdArr.find(".xiyao_yznr").find("select option:selected").text();//医嘱内容
					  temp1.bef08 = tdArr.find(".xiyao_yyts").val();//天数
					  temp1.bef09 = tdArr.find(".xiyao_dcyl").val();//剂量
					  temp1.bef11 = 1;//数量
					  temp1.bby01 = 0;//收费项目ID
					  temp1.bef13 = "";//样本部位
					  temp1.bef16 = tdArr.find(".xiyao_pinci").find("select option:selected").text();//频次
					  temp1.bef17 = tdArr.find(".xiyao_gycs").val();//次数
					  temp1.bef20 = tdArr.find(".xiyao_zxxz").find("select option:selected").attr("id");//带药性质
					  temp1.bck01 = bck01;//给药科室
					  temp1.bef23 = 1;//滴速
					  temp1.vaf59 = zuValue;//组号
					  temp1.vaf32 = "1";//正常还是给药途径
					  temp1.bda01 = "1";
					  temp1.bef24 = tdArr.find(".xiyao_sc").val()==""?0:tdArr.find(".xiyao_sc").val();//首次
					  bef1.push(temp1);
					}
					  //正常医嘱
					  var temp2 = configData1(tdArr,vaa01,vac01);//初始化公共参数
					  if (zu=="") 
					  {
						  temp2.rownr=rownr;
					  }
					  else
					  {
						  temp2.rownr="1";
					  }
					  temp2.bbx01c = tdArr.find(".xiyao_yznr").next().val();//项目ID
					  temp2.bef07 = tdArr.find(".xiyao_yznr").val();//医嘱内容
					  temp2.bef08 = tdArr.find(".xiyao_yyts").val();//天数
					  temp2.bef09 = tdArr.find(".xiyao_dcyl").val();//剂量
					  temp2.bef11 = tdArr.find(".xiyao_zl").val();//数量
					  temp2.bby01 = tdArr.find(".xiyao_yznr").next().next().val();//收费项目ID
					  temp2.bef13 = "";//样本部位
					  temp2.bef16 = tdArr.find(".xiyao_pinci").find("select option:selected").text();//频次
					  temp2.bef17 = tdArr.find(".xiyao_yyts").val();//次数
					  temp2.bef20 = tdArr.find(".xiyao_zxxz").find("select option:selected").attr("id");//带药性质
					  temp2.bck01 = tdArr.find(".xiyao_zxks").attr("id");//执行科室
					  temp2.bef23 = tdArr.find(".xiyao_disu").val();//执行科室//滴速
					  temp2.vaf59 = zuValue;//组号
					  temp2.vaf32 = "0";//正常还是给药途径
					  temp2.bda01 = "1";
					  temp2.bef24 = tdArr.find(".xiyao_sc").val()==""?0:tdArr.find(".xiyao_sc").val();//首次
					  bef1.push(temp2);
				 }
			 });
		}
		
		//中药
		function GetBef3(bef1) 
		{
			var bck01a = bck01;
			var tableObj = document.getElementById("");
			var temp1;
			count1++;
			var rownr = 0;
			var temp33 = [];
			$("#china_medicine_table tbody tr").each(function(i)
			{ 
					var tdArr = $(this);
					var flag = tdArr.find(".zhongyao_yznr").val(); //根据医嘱内容判断是否保存
					if (flag != "" && flag !=undefined) {
						if (i==0) {
							//方剂
							temp1 = configData1(tdArr, vaa01, vac01);
							temp1.rownr = rownr;
							temp1.bbx01c = $("#china_medicine_table tbody").find(".zhongyao_zyyf").find("select option:selected").val(); //用药用法的bbx01
							var jianfa = $("#china_medicine_table tbody").find(".zhongyao_jf").find("select option:selected").text();//煎法
							var adviceContent = tdArr.find(".zhongyao_yznr").val()
							+ " "+tdArr.find(".zhongyao_jz").find("select option:selected").text()+";";
							temp1.bef07 = "中药1付，" + $("#china_medicine_table tbody").find(".zhongyao_pc").find("select option:selected").text() + "，"
							+ $("#china_medicine_table tbody").find(".zhongyao_zyyf").find("select option:selected").text() + "，" + jianfa + "："
							+ adviceContent; //医嘱内容
							temp1.bef08 = 1;
							temp1.bef09 = 1;
							temp1.bef11 = 1;
							temp1.bby01 = 0;
							temp1.bef13 = "";
							temp1.bef16 = $("#china_medicine_table tbody").find(".zhongyao_pc").find("select option:selected").text();//频次
							temp1.bef17 = 1;
							temp1.bef20 = $("#china_medicine_table tbody").find(".zhongyao_zxxz").find("select option:selected").attr("id");//执行性质
							temp1.bck01 = $("#china_medicine_table tbody").find(".zhongyao_zxks").attr("id");//执行科室ID;
							temp1.bef23 = 0;
							temp1.vaf59 = 0;
							temp1.vaf32 = 1;
							temp1.bda01 = "8";
							temp1.bef24 = 0;
							
							}
						var adviceContent;
						if (i > 0) {
							adviceContent = tdArr.find(".zhongyao_yznr").val()
							+ tdArr.find(".zhongyao_jz").find("select option:selected").text()+";";
									//+ tdArr.eq(8).find("select option:selected").text()+";";
							temp1.bef07 = temp1.bef07 + " " + adviceContent; //医嘱内容
						}
						
						//中药
						rownr++;
						var temp2 = configData1(tdArr, vaa01, vac01);
						temp2.rownr = rownr;
						temp2.bbx01c = tdArr.find(".zhongyao_yznr").next().val();//诊疗项目ID---
						temp2.bef07 = tdArr.find(".zhongyao_yznr").val(); //医嘱内容
						temp2.bef08 = 1;
						temp2.bef09 = 1;
						temp2.bef11 = 1;
						temp2.bby01 = tdArr.find(".zhongyao_yznr").next().next().val(); //收费项目ID---
						temp2.bef13 = "";
						temp2.bef16 = $("#china_medicine_table tbody").find(".zhongyao_pc").find("select option:selected").text();//频次
						temp2.bef17 = 1;
						temp2.bef20 = $("#china_medicine_table tbody").find(".zhongyao_zxxz").find("select option:selected").attr("id");//执行性质
						temp2.bck01 = $("#china_medicine_table tbody").find(".zhongyao_zxks").attr("id");//执行科室ID;
						temp2.bef23 = 0;
						temp2.vaf59 = 0;
						temp2.vaf32 = "0";
						temp2.bda01 = "8";
						temp2.bef24 = 0;
						temp33.push(temp2);
						
						if (i == $("#china_medicine_table tbody tr").length - 1) {
							
							temp1.bef07 = temp1.bef07.substr(0,temp1.bef07.length-1);
							bef1.push(temp1);
							for(var k = 0;k<temp33.length;k++)
							{
								bef1.push(temp33[k]);
							}
							rownr++;
							//治疗
							var temp3 = configData1(tdArr, vaa01, vac01);
							temp3.rownr = rownr;
							temp3.bbx01c = $("#china_medicine_table tbody").find(".zhongyao_zyyf").find("select option:selected").val(); //煎法的bbx01
							temp3.bef07 = $("#china_medicine_table tbody").find(".zhongyao_zyyf").find("select option:selected").text();//煎法
							temp3.bef08 = 1;
							temp3.bef09 = 1;
							temp3.bef11 = 1;
							temp3.bby01 = 0;
							temp3.bef13 = "";
							temp3.bef16 = $("#china_medicine_table tbody").find(".zhongyao_pc").find("select option:selected").text();//频次
							temp3.bef17 = 1;
							temp3.bef20 = $("#china_medicine_table tbody").find(".zhongyao_zxxz").find("select option:selected").attr("id");//执行性质
							temp3.bck01 = $("#china_medicine_table tbody").find(".zhongyao_zxks").attr("id");//执行科室ID;
							temp3.bef23 = 0;
							temp3.vaf59 = 0;
							temp3.vaf32 = "0";
							temp3.bda01 = "8";
							temp3.bef24 = 0;
							bef1.push(temp3);
							
						}
					}
			});
		}
		//检验
		function GetBefL(bef1) 
		{
			var bck01a = bck01;
			$("#xk_jy_table tbody tr").each(function(i)
			{ 
				count1++;
				var tdArr = $(this);
				var flag =tdArr.find(".jianyan_yznr").val(); //医嘱内容
				if (flag != "" && flag !=undefined)  {
					//医嘱类别
					var zu = tdArr.find(".jianyan_zu").text();
					//检验
					  var temp2 = configData1(tdArr,vaa01,vac01);//初始化公共参数
					  temp2.rownr="0";//顺序
					  temp2.bbx01c = tdArr.find(".jianyan_yznr").next().val(); //诊疗项目ID---
					  temp2.bef07 = tdArr.find(".jianyan_yznr").val() //医嘱内容
					  temp2.bef08 = 0;//天数
					  temp2.bef09 = 0;//剂量
					  temp2.bef11 = 1;//数量
					  temp2.bby01 = 0;//收费项目ID
					  temp2.bef13 = tdArr.find(".jianyan_yblx").find("select option:selected").text();//样本
					  temp2.bef16 = "";//频次
					  temp2.bef17 = 1;//次数
					  temp2.bef20 = tdArr.find(".jianyan_zxxz").find("select option:selected").attr("id");//执行性质
					  temp2.bck01 = tdArr.find(".jianyan_zxks").find("select option:selected").val();//执行科室
					  temp2.bef23 = 0;//滴速
					  temp2.vaf59 = zu;//组号
					  temp2.vaf32 = "0";//正常还是给药途径
					  temp2.bda01 = "L";
					  temp2.bef24 = 0;//首次
					  bef1.push(temp2);
				}
			});
		}
		
		//检查
		function GetBefE(bef1) 
		{
			var bck01a = bck01;
		    $("#xk_jc_table tbody tr").each(function(i)
			{ 
		    	count1++;
		    	var tdArr = $(this);
				var flag = tdArr.find(".jiancha_yznr").val(); //医嘱内容
				if (flag != "" && flag !=undefined) {
					//医嘱类别
					var bda01 = "E";
					var zu = count1;
					//检查
					  var temp2 = configData1(tdArr,vaa01,vac01);//初始化公共参数
					  temp2.rownr="0";//顺序
					  temp2.bbx01c = tdArr.find(".jiancha_yznr").next().val(); //诊疗项目ID---
					  temp2.bef07 = tdArr.find(".jiancha_yznr").val(); //医嘱内容
					  temp2.bef08 = 0;//天数
					  temp2.bef09 = 0;//剂量
					  temp2.bef11 = 1;//数量
					  temp2.bby01 = 0;//收费项目ID
					  temp2.bef13 = "";//样本
					  temp2.bef16 = "";//频次
					  temp2.bef17 = 1;//次数
					  temp2.bef20 = tdArr.find(".jiancha_zxxz").find("select option:selected").attr("id");//执行性质
					  temp2.bck01 = tdArr.find(".jiancha_zxks").find("select option:selected").val();;//给药科室
					  temp2.bef23 = 0;//滴速
					  temp2.vaf59 = zu;//组号
					  temp2.vaf32 = "0";//正常还是给药途径
					  temp2.bda01 = "E";
					  temp2.bef24 = 0;//首次
					  bef1.push(temp2);
				}
			});
		}
		
		//手术
		function GetBefS(bef1) 
		{
			var bck01a = bck01;
			$("#xk_shoushu_table tbody tr").each(function(i)
			{ 
				count1++;
				var tdArr = $(this);
				var flag = tdArr.find(".shoushu_yznr").val();
				if (flag!="" && flag!=undefined) {
					//医嘱类别
					var bda01 = "S";
					var zu = count1;
					
					//主要手术
					  var temp1 = configData1(tdArr,vaa01,vac01);//初始化公共参数
					  temp1.rownr="0";//顺序
					  temp1.bbx01c = tdArr.find(".shoushu_yznr").next().val();
					  temp1.bef07 = tdArr.find(".shoushu_yznr").val();
					  temp1.bef08 = 1;//天数
					  temp1.bef09 = 0;//剂量
					  temp1.bef11 = 1;//数量
					  temp1.bby01 = 0;//收费项目ID
					  temp1.bef13 = "";//样本部位
					  temp1.bef16 = "";//频次
					  temp1.bef17 = 1;//次数
					  temp1.bef20 = tdArr.find(".shoushu_zxxz").find("option:selected").attr("id");//执行性质
					  temp1.bck01 = tdArr.find(".shoushu_zxks").find("option:selected").val();//执行科室ID
					  temp1.bef23 = 0;//滴速
					  temp1.vaf59 = zu;//组号
					  temp1.vaf32 = "0";//正常还是给药途径
					  temp1.bda01 = "S";
					  temp1.bef24 = 0;//首次
					  bef1.push(temp1);
					/**
					 * 附加手术医嘱
					 */
					var k = 1;
					$(".shoushu_fjss").each(function(j, ele) {
						if ($(ele).val()) {
							var temp99 = configData1(tdArr,vaa01,vac01);//初始化公共参数
							  temp99.rownr=k;//顺序
							  k++;
							  temp99.bbx01c = $(ele).next().val();
							  temp99.bef07 = $(ele).val();
							  temp99.bef08 = 1;//天数
							  temp99.bef09 = 0;//剂量
							  temp99.bef11 = 1;//数量
							  temp99.bby01 = 0;//收费项目ID
							  temp99.bef13 = "";//样本部位
							  temp99.bef16 = "";//频次
							  temp99.bef17 = 1;//次数
							  temp99.bef20 = tdArr.find(".shoushu_zxxz").find("option:selected").attr("id");//执行性质
							  temp99.bck01 = tdArr.find(".shoushu_zxks").find("option:selected").val();//执行科室ID
							  temp99.bef23 = 0;//滴速
							  temp99.vaf59 = zu;//组号
							  temp99.vaf32 = "0";//正常还是给药途径
							  temp99.bda01 = "S";
							  temp99.bef24 = 0;//首次
							  bef1.push(temp99);
						}
					});
					
					//麻醉
					var mazuiText = tdArr.find(".shoushu_mzfs").find("input:checked").val();
					if (mazuiText!="" && mazuiText!=undefined) {
						var mazuiArr = tdArr.find(".shoushu_mzfs").find("input:checked").val().split("|");
						var temp3 = configData1(tdArr,vaa01,vac01);//初始化公共参数
						  temp3.rownr=k + "";//顺序
						  temp3.bbx01c = mazuiArr[1];
						  temp3.bef07 = tdArr.find(".shoushu_mzfs").find("input:checked").next().text();
						  temp3.bef08 = 1;//天数
						  temp3.bef09 = 0;//剂量
						  temp3.bef11 = 1;//数量
						  temp3.bby01 = 0;//收费项目ID
						  temp3.bef13 = "";//样本部位
						  temp3.bef16 = "";//频次
						  temp3.bef17 = 1;//次数
						  temp3.bef20 = tdArr.find(".shoushu_zxxz").find("option:selected").attr("id");//执行性质
						  temp3.bck01 = tdArr.find(".shoushu_zxks").find("option:selected").val();//执行科室ID
						  temp3.bef23 = 0;//滴速
						  temp3.vaf59 = zu;//组号
						  temp3.vaf32 = "0";//正常还是给药途径
						  temp3.bda01 = mazuiArr[0];
						  temp3.bef24 = 0;//首次
						  bef1.push(temp3);
					}
				}
			});
		}
		
		//治疗
		function GetBefT(bef1)
		{
			var bck01a = bck01;
		    $("#xk_zhiliao_table tbody tr").each(function(i)
			{ 
		    	count1++;
		    	var tdArr = $(this);
				var flag = tdArr.find(".zhiliao_yznr").val(); //医嘱内容
				if (flag != "" && flag !=undefined) {
					//医嘱类别
					var bda01 = "T";
					var zu = count1;
					//检查
					  var temp2 = configData1(tdArr,vaa01,vac01);//初始化公共参数
					  temp2.rownr="0";//顺序
					  temp2.bbx01c = tdArr.find(".zhiliao_yznr").next().val(); //诊疗项目ID---
					  temp2.bef07 = tdArr.find(".zhiliao_yznr").val(); //医嘱内容
					  temp2.bef08 = 0;//天数
					  temp2.bef09 = 0;//剂量
					  temp2.bef11 = 1;//数量
					  temp2.bby01 = 0;//收费项目ID
					  temp2.bef13 = "";//样本
					  temp2.bef16 = "";//频次
					  temp2.bef17 = 1;//次数
					  temp2.bef20 = tdArr.find(".zhiliao_zxxz").find("select option:selected").attr("id");//执行性质
					  temp2.bck01 = tdArr.find(".zhiliao_zxks").find("select option:selected").val();//执行科室ID
					  temp2.bef23 = 0;//滴速
					  temp2.vaf59 = zu;//组号
					  temp2.vaf32 = "0";//正常还是给药途径
					  temp2.bda01 = "T";
					  temp2.bef24 = 0;//首次
					  bef1.push(temp2);
				}
			});
		}
		
		/**
		 * 组合vaf1公共基础数据
		 * @param vaa01
		 * @param vac01
		 * @param tableObj
		 * @param i
		 * @returns {___anonymous_vaf1t}
		 */
		function configData1(tdArr,vaa01,vac01)
		{
			  var vaf1t = {};
			  vaf1t.bbx01b = "0";//1
			  vaf1t.bef05= "2";//1
			  vaf1t.bef10 = "";//1
			  vaf1t.bef14 = "";//1
			  vaf1t.bef15 = "";//1
			  vaf1t.bef18 = 1;//1
			  vaf1t.bef19 = "";//1
			  vaf1t.bef22 = "";//1
			  return vaf1t;
		}
		
		
		
		
		
		
/*每一个checkbox添加事件*/
function zlsSlectCheckobx(){
	 /*选择所有*/
	$("#zhiliaoAdvice thead").on('click','[type="checkbox"]',function(e){
	    if($(this).prop('checked')){
	    	$("#zhiliaoAdvice").find('tbody [type="checkbox"]').prop('checked',true);
	    }else{
	    	$("#zhiliaoAdvice").find('tbody [type="checkbox"]').prop('checked',false);
	    }
	});
	$("#zhiliaoAdvice tbody").on('change','[type="checkbox"]',function(e){
		//阻止事件冒泡到tr上
		var evt = e || window.event;
		evt.stopPropagation();
		//1.得到当前的tr
		var $tr = $(this).parents('tr');
		//2.得到所有的tr
		var $trs = $("#zhiliaoAdvice tbody").find('tr');
		//3.得到与当前tr是一组的tr
		var $sameGroupTrs;
		var tr_groupId = $tr.attr('groupid');
		if(tr_groupId){
			$sameGroupTrs = $trs.filter('[groupid='+tr_groupId+']');
		}
		//4.根据checkbox的选中或不选中，
		if($(this).prop('checked')){
			if($sameGroupTrs && $sameGroupTrs.length > 0){
				$sameGroupTrs.each(function(i, ele){
					if(i==0){// tr的第一项中的checkbox已经改变
						return;
					}else{
						$(ele).find('.checkbox-default').prop('checked', true);
					}
				});
			}
		}else{
			if($sameGroupTrs && $sameGroupTrs.length > 0){
				$sameGroupTrs.each(function(i, ele){
					if(i==0){// tr的第一项中的checkbox已经改变
						return;
					}else{
						$(ele).find('.checkbox-default').prop('checked', false);
					}
				});
			}
			$("#zhiliaoAdvice").prop('checked',false);
		}
	});
}
